package com.calvin.study.shiro;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;

public class RedisCacheManager implements CacheManager {
	
	private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();

	@Override
	public <K, V> Cache<K, V> getCache(String cacheName) throws CacheException {
		Cache<K, V> c = caches.get(cacheName);
		if(null == c) {
			//设置认证/授权缓存的key
			c = new RedisCache<K, V>("("+cacheName+")" + "shiro_cache:");
			caches.put(cacheName, c);
		}
		return c;
	}

}
